package com.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.entity.Cartltem;
import com.entity.Orders;
import com.service.CartService;
import com.service.OrdersService;







@Controller
public class OrdersController {
	@Resource
	private OrdersService os;
	@Resource
	private CartService cs;
	@Resource
	private HttpServletRequest request;
	@Resource
	private HttpServletResponse response;
	@Resource
	private HttpSession session;
	@RequestMapping("orders")
	public ModelAndView orders(Model model,Orders order){
		int order_id=os.orders(order.getDesk(),order);
		List<Cartltem> list =os.finall(order_id);
		session.setAttribute("list", list);
		session.setAttribute("desk", order.getDesk());
		session.setAttribute("order_id", order_id);
		ModelAndView mv=new ModelAndView("/productPage?page=1");
		return mv;
	}
	@RequestMapping("pushOrder")
//	@Transactional//这里开启事务没有用
	public String pushOrder(Model model){
		int orders_id=(int) session.getAttribute("order_id");
		os.pushOrder(orders_id);
		cs.pushcart(orders_id);
		session.setAttribute("list", null);
		return "/orders";
	}
	
	@RequestMapping("finOrder")
	public String finOrder(Model model){
		int order_id=(int)session.getAttribute("order_id");
		List<Cartltem> list =os.finall(order_id);
		session.setAttribute("list", list);
		
		return "/showcart.jsp";
	}
}
